package com.yinhe.system.service.impl;

import com.yinhe.common.annotation.DataScope;
import com.yinhe.common.utils.DateUtils;
import com.yinhe.system.domain.YhRiskNotification;
import com.yinhe.system.mapper.YhRiskNotificationMapper;
import com.yinhe.system.service.IYhRiskNotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.Validator;
import java.util.List;

/**
 * 风险告知单Service业务层处理
 * 
 * @author yinhe
 * @date 2022-07-13
 */
@Service
public class YhRiskNotificationServiceImpl implements IYhRiskNotificationService 
{
    @Autowired
    private YhRiskNotificationMapper yhRiskNotificationMapper;
    @Autowired
    protected Validator validator;
    /**
     * 查询风险告知单
     * 
     * @param id 风险告知单主键
     * @return 风险告知单
     */
    @Override
    public YhRiskNotification selectYhRiskNotificationById(Long id)
    {
        return yhRiskNotificationMapper.selectYhRiskNotificationById(id);
    }

    /**
     * 查询风险告知单列表
     * 
     * @param yhRiskNotification 风险告知单
     * @return 风险告知单
     */
    @Override
    @DataScope(deptAlias = "n", userAlias = "n")
    public List<YhRiskNotification> selectYhRiskNotificationList(YhRiskNotification yhRiskNotification)
    {
        return yhRiskNotificationMapper.selectYhRiskNotificationList(yhRiskNotification);
    }

    /**
     * 新增风险告知单
     * 
     * @param yhRiskNotification 风险告知单
     * @return 结果
     */
    @Override
    public int insertYhRiskNotification(YhRiskNotification yhRiskNotification)
    {
        yhRiskNotification.setCreateTime(DateUtils.getNowDate());
        return yhRiskNotificationMapper.insertYhRiskNotification(yhRiskNotification);
    }

    /**
     * 修改风险告知单
     * 
     * @param yhRiskNotification 风险告知单
     * @return 结果
     */
    @Override
    public int updateYhRiskNotification(YhRiskNotification yhRiskNotification)
    {
        yhRiskNotification.setUpdateTime(DateUtils.getNowDate());
        return yhRiskNotificationMapper.updateYhRiskNotification(yhRiskNotification);
    }

    /**
     * 批量删除风险告知单
     * 
     * @param ids 需要删除的风险告知单主键
     * @return 结果
     */
    @Override
    public int deleteYhRiskNotificationByIds(Long[] ids)
    {
        return yhRiskNotificationMapper.deleteYhRiskNotificationByIds(ids);
    }

    /**
     * 删除风险告知单信息
     * 
     * @param id 风险告知单主键
     * @return 结果
     */
    @Override
    public int deleteYhRiskNotificationById(Long id)
    {
        return yhRiskNotificationMapper.deleteYhRiskNotificationById(id);
    }

    /**
     * 导入风险告知单数据
     *
     * @param userList 用户数据列表
     * @param isUpdateSupport 是否更新支持，如果已存在，则进行更新数据
     * @param operName 操作用户
     * @return 结果
     */
    @Override
    public String importRiskNotification(List<YhRiskNotification> riskNotificationList, Boolean isUpdateSupport)
    {
        int successNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        for (YhRiskNotification riskNotification : riskNotificationList) {
            long represent = Long.parseLong(riskNotification.getRepresentativeOffice());
            riskNotification.setDeptId(represent);
            this.insertYhRiskNotification(riskNotification);
            successNum++;
        }
        successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条");
        return successMsg.toString();
    }
}
